from access.core.codesnippetpattern import CodeSnippetPattern
from access.core.programminglanguage import ProgrammingLanguage
from access.core.utterancepattern import UtterancePattern
import unittest

class DefaultProgrammingLanguage(ProgrammingLanguage): pass

class SimpleProgrammingLanguage(ProgrammingLanguage):
  def DefineUtterancePatterns(self):
    vocabulary = {}
    print 'self vocab'
    print self.vocabulary
    print 'vocab'
    print vocabulary
    vocabulary['en-us'] = \
    [
     UtterancePattern('create-tag',
                      '[create] tag'),
     ]
    return vocabulary
  
  def DefineSnippetPatterns(self):
    snippets = \
    [
     CodeSnippetPattern('create-tag',
                        '<${tag}>{{cursor}}</${tag}>'),
     ]
    return snippets
  
  def __init__(self):
    ProgrammingLanguage.__init__(self)

class SimpleVariableProgrammingLanguage(ProgrammingLanguage):
  tag = ['html', 'body']

  def DefineUtterancePatterns(self):
    vocabulary = {}
    vocabulary['en-us'] = \
    [
     UtterancePattern('create-{{tag}}',
                      '[create] {{tag}}',
                      tag = self.tag),
     ]
    return vocabulary
  
  def DefineSnippetPatterns(self):
    snippets = \
    [
     CodeSnippetPattern('create-{{tag}}',
                        '<{{tag}}>{{cursor}}</{{tag}}>',
                        tag = self.tag),
     ]
    return snippets

class FullyFeaturedProgrammingLanguage(ProgrammingLanguage):
  tag = ['html', 'body']

  def DefineUtterancePatterns(self):
    vocabulary = {}
    vocabulary['en-us'] = \
    [
     UtterancePattern('create-tag',
                      '[create] tag'),
     UtterancePattern('create-{{tag}}',
                      '[create] {{tag}}',
                      tag = self.tag),
     ]
    return vocabulary
  
  def DefineSnippetPatterns(self):
    snippets = \
    [
     CodeSnippetPattern('create-tag',
                        '<${tag}>{{cursor}}</${tag}>'),
     CodeSnippetPattern('create-{{tag}}',
                        '<{{tag}}>{{cursor}}</{{tag}}>',
                        tag = self.tag),
     ]
    return snippets

class ProgrammingLanguageTest(unittest.TestCase):
  def testDefaultEndToEnd(self):
    language = DefaultProgrammingLanguage()
    self.assertEqual(0,
                     len(language.vocabulary), 
                     'Unexpected vocabulary in default programming language.')
    self.assertEqual(0,
                     len(language.snippets), 
                     'Unexpected snippet in default programming language.')

  def testSimpleEndToEnd(self):
    language = SimpleProgrammingLanguage()
    print language
    self.assertEqual(1,
                     len(language.vocabulary), 
                     'Expecting only one utterance in language''s vocabulary.')
    self.assertEqual(1,
                     len(language.snippets))

  def testSimpleVariableEndToEnd(self):
    language = SimpleVariableProgrammingLanguage()
    print language

  def testFullyFeaturedEndToEnd(self):
    language = FullyFeaturedProgrammingLanguage()
    print language
